﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShowNative : MonoBehaviour {
    
    AndroidJavaClass javaUnityPlayer;
    AndroidJavaObject unityActivity;
    AndroidJavaClass m_javaXYZAndroidUnity;
    // Use this for initialization
    void Start () {
        
    }

    private void getJavaClasses()
    {
        Debug.Log("getting java classes..");
        this.javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        Debug.Log("got javaUnityPlayer");
        this.unityActivity = this.javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        Debug.Log("got Unity Activity");
        this.m_javaXYZAndroidUnity = new AndroidJavaClass("com.vixo.unityandroid.XYZActivityHelper");
        Debug.Log("got XYZAndroidUnity");
    }

    private AndroidJavaClass javaXYZAndroidUnity {
        get {
            if (m_javaXYZAndroidUnity == null)
            {
                getJavaClasses();
            }
            return m_javaXYZAndroidUnity;
        }
    }
	
	// Update is called once per frame
	void Update () {
		
	}

    private void OnGUI()
    {
        if (GUI.Button(new Rect(0, 100, 200, 50), "视频播放"))
        {
            ExecNative("showVixoVideoPlayFrag");
        }

        if (GUI.Button(new Rect(0, 200, 200, 50), "Show Any Activity."))
        {
            ExecNative("showAnyActivity");
        }

        if (GUI.Button(new Rect(0, 300, 200, 50), "Show Any Fragment."))
        {
            ExecNative("showAnyFragment");
        }
    }

    private void ExecNative(string m)
    {
        javaXYZAndroidUnity.CallStatic(m,new object[] {this.unityActivity});
    }

    public void GetWorkList(String para)
    {
        //Todo: 获取作品列表
        string videoList = @"5390DB3952549DCF92E1E9E8165DA338.mp4,20A66C8B0CD46A26037EDA2F64A99E5C.mp4,qjdh_clip.mp4,JIANGZHENDE_clip.mp4,A1C1259A5DD51898632D1160EC01384A.mp4";
        this.javaXYZAndroidUnity.CallStatic("workListResult", new object[] { this.unityActivity ,videoList });
    }

}
